using System;

namespace SQLPXBase
{
    public class MSSQLServerConnectionString : Interfaces.ISQLConnectionString
    {
        private string serverSql = "";
        private string dbSql = "";
        private string utente = "";
        private string password = "";


        public MSSQLServerConnectionString(string serverSql, string dbSql, string utente, string password)
        {
            this.serverSql = serverSql;
            this.dbSql = dbSql;
            this.utente = utente;
            this.password = password;

        }

        #region G/S

        public string ServerSql
        {
            get { return serverSql; }
        }

        public string DbSql
        {
            get { return dbSql; }
        }

        public string Utente
        {
            get { return utente; }
        }

        public string Password
        {
            get { return password; }
        }

        #endregion

        public string ProviderName { get { return "System.Data.SqlClient"; } }

        public string ConnectionString
        {
            get
            {
                if (serverSql == "" || dbSql == "")
                    throw new Exception("Connection string incompleta: controllare i parametri del collegamento");

                if (!string.IsNullOrEmpty(utente) && utente.Trim() != "")
                    return
                        string.Format(
                            "Persist Security Info=False;User ID={0};Password={1};Initial Catalog={2};Data Source={3}",
                            utente, password, dbSql, serverSql);

                return
                    string.Format(
                        "Persist Security Info=False;Integrated Security=True;Initial Catalog={0};Data Source={1}",
                        dbSql, serverSql);
            }

        }
    }

    public class OleDbConnectionString : Interfaces.ISQLConnectionString
    {
        private string connectionString = "";

        public OleDbConnectionString(string connectionString)
        {
            this.connectionString = connectionString;
        }

        public string ConnectionString { get { return connectionString; } }
        public string ProviderName { get { return "System.Data.OleDb"; } }
    }

}
